
class ScorePanel {
    score = 0;
    level = 1;
    scoreEle: HTMLElement;
    levelEle: HTMLElement;


    //等级上限
    maxLevel: number;
    //满多少分升一级
    scoreUp:number;
    constructor(maxLevel: number = 10,scoreUp:number = 10) {
        this.scoreEle = document.getElementById('score')!;
        this.levelEle = document.getElementById('level')!;
        this.maxLevel = maxLevel;
        this.scoreUp = scoreUp;
    }

    //加分函数

    addScore() {
        this.scoreEle.innerHTML = ++this.score + '';
        if(this.score % this.scoreUp == 0){
            this.levelUp();
        }
    }

    //升级函数

    levelUp() {
        if (this.level < this.maxLevel) {
            this.levelEle.innerHTML = ++this.level + '';
        }
    }

}


export default ScorePanel;